package org.skydiveapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;

public class NotesEditActivity extends Activity
{	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		// init ui
		initializeUI();
	}
		
	private void initializeUI()
	{
		// show view
		setContentView(R.layout.notes_view);
		
		// set header text
		TextView headerTextView = (TextView)findViewById(R.id.EditHeaderTextView);
		headerTextView.setText(R.string.notes_editor_notes_label);

		// set notes
		Bundle extras = getIntent().getExtras();
		String notes = (extras == null ? "" : extras.getString(Constants.EXTRA_NOTES));
		EditText nField = (EditText)findViewById(R.id.NotesField);
		nField.setText(notes);
	}
	
	private void save()
	{
		// get notes
		EditText nField = (EditText)findViewById(R.id.NotesField);
		String notes = nField.getText().toString();

		// set result
		Intent intent =  new Intent();
		intent.putExtra(Constants.EXTRA_NOTES, notes);
		setResult(RESULT_OK, intent);
		finish();
	}
	
	@Override
	public void onBackPressed()
	{
		save();
		super.onBackPressed();
	}
}
